//
//  ZZEditUserCell.m
//  QQplayground
//
//  Created by zhangxy on 2018/8/7.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "ZZEditUserCell.h"

@interface ZZEditUserCell()<UITextViewDelegate>


@end

@implementation ZZEditUserCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    [_btnBoy setImage:[UIImage imageNamed:@"设置 选中"] forState:UIControlStateSelected];
    [_btnBoy setImage:[UIImage imageNamed:@"设置 未选中"] forState:UIControlStateNormal];
    [_btnBoy setImage:[UIImage imageNamed:@"设置 选中"] forState:UIControlStateHighlighted];
    [_btnBoy setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    [_btnBoy.titleLabel setFont:FontFiftent];
    [_btnBoy setTitle:@"男" forState:0];
    
    
    [_btnGirl setImage:[UIImage imageNamed:@"设置 选中"] forState:UIControlStateSelected];
    [_btnGirl setImage:[UIImage imageNamed:@"设置 未选中"] forState:UIControlStateNormal];
    [_btnGirl setImage:[UIImage imageNamed:@"设置 选中"] forState:UIControlStateHighlighted];
    [_btnGirl setTitleColor:UIColorFromRGB(TextSizeOneColor) forState:0];
    [_btnGirl.titleLabel setFont:FontFiftent];
    [_btnGirl setTitle:@"女" forState:0];
    
    [_btnGirl addTarget:self action:@selector(genderClick:) forControlEvents:UIControlEventTouchUpInside];
    [_btnBoy addTarget:self action:@selector(genderClick:) forControlEvents:UIControlEventTouchUpInside];
    
    [_labText setFont:FontFiftent];
    
    [_labTag setFont:FontFiftent];
    [_labTag setTextColor:UIColorFromRGB(TextSizeOneColor)];
    
    [_txtContent setFont:FontFiftent];
    [_txtContent setPlaceholderColor:UIColorFromRGB(TextSizeEightColor)];
    [_txtContent setTextColor:UIColorFromRGB(TextSizeOneColor)];
    _txtContent.delegate = self;
}

-(void)genderClick:(UIButton *) btn{
    if([btn isEqual:_btnGirl]){
        _btnGirl.selected = YES;
        _btnBoy.selected  = NO;
        self.tempModel.user_gender = 0;
    }else{
        _btnGirl.selected = NO;
        _btnBoy.selected  = YES;
        
        self.tempModel.user_gender = 1;
    }

    if (_delegate && [self.delegate respondsToSelector:@selector(onValueChange:data:)]) {
        
        [self.delegate onValueChange:2 data:self.tempModel];
    }
}


-(void)dataToView:(NSDictionary *) item{
    _tempDict = item;
    _btnGirl.hidden = YES;
    _btnBoy.hidden  = YES;
    _labText.hidden = YES;
    _txtContent.hidden = YES;
    
    
    int code = [item[@"code"] intValue];
    NSString *tag = item[@"title"];
    NSString *value = item[@"value"];
    
    [_labTag setText:convertToString(tag)];
    if(code == 1 || code == 4 || code == 7){
        _txtContent.hidden = NO;
        
        if(convertToString(value).length > 0){
            [_txtContent setText:value];
        }else{
            [_txtContent setPlaceholder:tag];
        }
    }else if(code == 2){
        _btnBoy.hidden = NO;
        _btnGirl.hidden = NO;
        
        _btnGirl.selected = NO;
        _btnBoy.selected  = NO;
        if([value intValue]  == 1){
            _btnBoy.selected  = YES;
        }else{
            _btnGirl.selected = YES;
        }
    }else{
        _labText.hidden = NO;
        if(convertToString(value).length > 0){
            [_labText setText:value];
            [_labText setTextColor:UIColorFromRGB(TextSizeOneColor)];
        }else{
            [_labText setText:tag];
            [_labText setTextColor:UIColorFromRGB(TextSizeEightColor)];
        }
    }
    
    
}



-(void)textViewDidChange:(ZTextView *)textView{
    int code = [_tempDict[@"code"] intValue];
    if(code == 1){
        self.tempModel.user_name = convertToString(textView.text);
    }else if(code == 4){
        self.tempModel.user_qq = convertToString(textView.text);
    }else if(code == 7){
        self.tempModel.user_sign = convertToString(textView.text);
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(onValueChange:data:)]) {
        
        [self.delegate onValueChange:code data:self.tempModel];
    }
}

-(void)textViewDidBeginEditing:(ZTextView *)textView{
    if(self.delegate && [self.delegate respondsToSelector:@selector(didKeyboardWillShow:view1:)]){
        [self.delegate didKeyboardWillShow:self.indexPath view1:textView];
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
